import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { viteMockServe } from 'vite-plugin-mock'

export default defineConfig(({ command }) => {
  return {
    main: {
      plugins: [externalizeDepsPlugin()]
    },
    preload: {
      plugins: [externalizeDepsPlugin()]
    },
    renderer: {
      resolve: {
        alias: {
          '@renderer': resolve('src/renderer/src')
        }
      },
      plugins: [
        vue(),
        Components({
          dirs: ['src/components'],
          resolvers: [ElementPlusResolver()],
          extensions: ['vue'],
          dts: 'types/components.d.ts',
          directoryAsNamespace: true
        }),
        AutoImport({
          imports: ['vue', 'vue-router', 'vue-i18n'],
          dts: 'types/auto-imports.d.ts',
          resolvers: [ElementPlusResolver()],
          dirs: ['src/composables', 'src/types/union.d.ts']
        }),
        viteMockServe({
          mockPath: 'mock', // mock文件夹路径
          enable: command === 'serve' // 只有开发环境才开启mock
        })
      ]
    }
  }
})
